package com.hs.jhzd.repository;

import com.hs.jhzd.entity.JhJyzyglEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface JhJyzyglRepository extends JpaRepository<JhJyzyglEntity, String> {

    @Query("select y from JhJyzyglEntity y where y.zyfl = ?1  ")
    public List<JhJyzyglEntity> findByType(String type);
    @Query(value ="select y from JhJyzyglEntity y where  (:jsbh is null or y.jsbh=:jsbh)  and y.zyfl=1",countQuery = "select count(y) from JhJyzyglEntity y where  (:jsbh is null or y.jsbh=:jsbh) and y.zyfl=1")
    public Page<JhJyzyglEntity> findByJsbh(@Param("jsbh") String jsbh, Pageable pageable);
    @Query("select y from JhJyzyglEntity y where  (:jsbh is null or y.jsbh=:jsbh)  and y.zyfl=1")
    public List<JhJyzyglEntity> findByJsbhNew(@Param("jsbh") String jsbh, Pageable pageable);

    public List<JhJyzyglEntity>findTop3ByJsbhAndZyflAndLxOrderBySjcDesc(String jsbh,String zyfl,String lx);

    public List<JhJyzyglEntity>findByJsbhAndZyfl(String jsbh,String zyfl);

    @Query(value="select zybh from jh_jyzygl where  zyfl=1 order by sjc DESC limit  1",nativeQuery=true)
    String findZybh();
}
